package sketch.generator;

import sketch.SMethod;
import sketch.SketchSequence;
import sketch.ValueChoice;
import sketch.skeleton.Skeleton;
import sketch.skeleton.SkeletonCreator;
import sketch.subject.TreeMap;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;


public class UnitTestGeneratorTest extends TestCase {
	
	public static Test suite() {
        return new TestSuite(UnitTestGeneratorTest.class);
    }
	
	public void setUp() {
		GenTests.reset(TreeMap.class);
	}
	
	public void testUnitTestGenerator() {
		
		TreeMap tree = new TreeMap();
		SMethod smethod = SMethod.instance(tree, "put(int)");
		ValueGenerator<Integer> valueGen = ValueChoice.getIntPool(1, 1, 1); 
		SequenceGenerator<SketchSequence> putgenerator = new SingleSequenceGenerator<SketchSequence>(tree, smethod, valueGen);
		int putCount = 0;
		while(putgenerator.hasNext()) {
			System.out.println(putgenerator.next());
			putCount++;
		}
		assertTrue(putCount == 1);
		putgenerator.reset();
		
		
		smethod = SMethod.instance(tree, "put(int)", "remove(int)", "containsKey(int)");
		valueGen = ValueChoice.getIntPool(5, 1, 20); 
		SequenceGenerator<SketchSequence> randomgenerator = new RandomSequenceGenerator<SketchSequence>(tree, smethod, valueGen);
		int randomCount = 0;
		while(randomgenerator.hasNext()) {
			System.out.println(randomgenerator.next());
			randomCount ++;
		}
		assertTrue(randomCount == 1);
		randomgenerator.reset();
		
		smethod = SMethod.instance(tree, "put(int)");
		valueGen = ValueChoice.getIntPool(4, 1, 20); 
		ExhaustiveSequenceGenerator<SketchSequence, Integer> exhaustivegenerator
		    = new ExhaustiveSequenceGenerator<SketchSequence, Integer>(tree, smethod, valueGen);
		int exhaustiveCount = 0;
		while(exhaustivegenerator.hasNext()) {
			System.out.println(exhaustivegenerator.next());
			exhaustiveCount++;
		}
		//System.out.println(exhaustiveCount);
		assertTrue(exhaustiveCount == 4*4*4*4 + 4*4*4 + 4*4 + 4);
		exhaustivegenerator.reset();
		
		//Skeleton skeleton = new SkeletonCreator("./tests/sketch/generator/ExampleSketchTest.java").createSkeleton();
		UnitTestGenerator<SketchSequence> unitTestGen = new UnitTestGenerator<SketchSequence>(/*skeleton,*/ putgenerator,  exhaustivegenerator);
		
		//System.out.println(skeleton.toCodeString());
		
		int count = 0;
		
		while(unitTestGen.hasNext()) {
			System.out.println((++count) + "th sequence:");
			SketchSequence generated = unitTestGen.next();
			System.out.println(generated.toString());
			System.out.println();
		}
		
		System.out.println("Create: " + exhaustiveCount + " tests in total!");
		assertTrue(count == exhaustiveCount);
	}
}
